<?php

function mean($number)
{
    // 初始化
    $sum = 0;

    $size = count($number);

    for ($i = 0; $i < $size; $i++) {
        $sum += $number[$i];
    }

    $average = $sum / $size;

    return $average;
}

function meanO(){
    $sum = 0;

    $size = func_num_args();

    for($i = 0;$i < $size;$i++){
        $sum += func_get_arg($i);
    }

    $arerage = $sum / $size;

    return $arerage;
}

function meanT(){
    $sum = 0;

    $size = func_num_args();

    foreach (func_get_args() as $arg){
        $sum += $arg;
    }

    $average = $sum / $size;

    return $average;
}
//$mean = mean([96,93,98,98]);
//$mean = meanO(97,93,98,98);
//$mean = meanT(97,93,98,98);


function &array_find_value($needle, &$haystack){
    foreach ($haystack as $key =>$value){
        if($needle == $value){
           // return $haystack[$key];
            $match = $haystack[$key];
        }
    }
    //return "$match is found in position $key"; // 这是不合法的 引用返回 必须返回一个变量的引用
    return $match;
}

$artists = ['jaja','sisi','doors','The Doors'];
$band = & array_find_value('The Doors', $artists);

$minnesota = [
    'Bob Dylan',
    'F.Scott Fitzgerald',
    'Prince',
    'Charles Schultz'
];

$prince = &array_find_value('Prince',$minnesota);

$prince = '0(+>';

var_dump($minnesota);

function array_find_values($needle, &$haystack){
    foreach ($haystack as $key =>$value){
        if($needle == $value){
           return $key;
        }
    }
}

$prince = array_find_values('Prince',$minnesota);

$minnesota[$prince] = '0(+>';


$prince = &array_find_value('Prince',$minnesota);

var_dump($minnesota);
